' ref: Xceed DataGrid for WPF Sample Code [GroupingItem.vb]

Imports System.ComponentModel
Imports System.Collections.ObjectModel
Imports System.Windows.Data
Imports Xceed.Wpf.DataGrid

Namespace Grouping
    Public Class GroupingItem
        Public Sub New()
        End Sub

        Private _description As String
        Public Property Description() As String
            Get
                Return _description
            End Get
            Set(ByVal value As String)
                _description = value
            End Set
        End Property

        Private _groupDescriptions As New ObservableCollection(Of GroupDescription)
        Public ReadOnly Property GroupDescriptions() As ObservableCollection(Of GroupDescription)
            Get
                Return _groupDescriptions
            End Get
        End Property

        Public Overloads Function Equals(ByVal groupDescriptions As ObservableCollection(Of GroupDescription)) As Boolean
            If groupDescriptions Is Nothing Then
                Return False
            End If

            If groupDescriptions.Count <> _groupDescriptions.Count Then
                Return False
            End If

            Dim i As Integer = 0

            For i = 0 To _groupDescriptions.Count - 1
                If Not _groupDescriptions(i) Is groupDescriptions(i) Then
                    Dim propertyGroupDesc1 = TryCast(_groupDescriptions(i), PropertyGroupDescription)
                    Dim propertyGroupDesc2 = TryCast(groupDescriptions(i), PropertyGroupDescription)

                    If (Not propertyGroupDesc1 Is Nothing) AndAlso (Not propertyGroupDesc2 Is Nothing) Then
                        If propertyGroupDesc1.PropertyName <> propertyGroupDesc2.PropertyName Then
                            Return False
                        End If
                    Else
                        Dim dataGridGroupDesc1 = TryCast(_groupDescriptions(i), DataGridGroupDescription)
                        Dim dataGridGroupDesc2 = TryCast(groupDescriptions(i), DataGridGroupDescription)

                        If (Not dataGridGroupDesc1 Is Nothing) AndAlso (Not dataGridGroupDesc2 Is Nothing) Then
                            If dataGridGroupDesc1.PropertyName <> dataGridGroupDesc2.PropertyName Then
                                Return False
                            End If
                        Else
                            Return False
                        End If
                    End If
                End If
            Next

            Return True
        End Function

    End Class
End Namespace
